package com.ruoyi.web.ydz.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.web.ydz.domain.LeaveBoard;
import com.ruoyi.web.ydz.service.ILeaveBoardService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 留言板Controller
 * 
 * @author ruoyi
 * @date 2024-11-08
 */
@RestController
@RequestMapping("/ydz/leaveBoard")
public class LeaveBoardController extends BaseController
{
    @Autowired
    private ILeaveBoardService leaveBoardService;

    /**
     * 查询留言板列表
     */
    @PreAuthorize("@ss.hasPermi('ydz:leaveBoard:list')")
    @GetMapping("/list")
    public TableDataInfo list(LeaveBoard leaveBoard)
    {
        startPage();
        List<LeaveBoard> list = leaveBoardService.selectLeaveBoardList(leaveBoard);
        return getDataTable(list);
    }

    /**
     * 导出留言板列表
     */
    @PreAuthorize("@ss.hasPermi('ydz:leaveBoard:export')")
    @Log(title = "留言板", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, LeaveBoard leaveBoard)
    {
        List<LeaveBoard> list = leaveBoardService.selectLeaveBoardList(leaveBoard);
        ExcelUtil<LeaveBoard> util = new ExcelUtil<LeaveBoard>(LeaveBoard.class);
        util.exportExcel(response, list, "留言板数据");
    }

    /**
     * 获取留言板详细信息
     */
    @PreAuthorize("@ss.hasPermi('ydz:leaveBoard:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(leaveBoardService.selectLeaveBoardById(id));
    }

    /**
     * 新增留言板
     */
    @PreAuthorize("@ss.hasPermi('ydz:leaveBoard:add')")
    @Log(title = "留言板", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    public AjaxResult add(@RequestBody LeaveBoard leaveBoard)
    {
        return toAjax(leaveBoardService.insertLeaveBoard(leaveBoard));
    }

    /**
     * 修改留言板
     */
    @PreAuthorize("@ss.hasPermi('ydz:leaveBoard:edit')")
    @Log(title = "留言板", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody LeaveBoard leaveBoard)
    {
        return toAjax(leaveBoardService.updateLeaveBoard(leaveBoard));
    }

    /**
     * 删除留言板
     */
    @PreAuthorize("@ss.hasPermi('ydz:leaveBoard:remove')")
    @Log(title = "留言板", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(leaveBoardService.deleteLeaveBoardByIds(ids));
    }
}
